﻿using CalligraphyEditor.CalligraphyData;
using CalligraphyEditor.ViewModel;
using DevExpress.Xpf.Grid;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CalligraphyEditor
{
    /// <summary>
    /// Interaction logic for DevRubbings.xaml
    /// </summary>
    public partial class DevRubbings : Page,IPage
    {
        private VMRubbings _vm;
        public DevRubbings(T_StelePaper sp)
        {
            InitializeComponent();
            _vm = new VMRubbings(sp);
            Gcl_Rubbings.DataContext = _vm.Cvs;
            Cmb_Dynast.ItemsSource = VMBaseData.Dynast;
        }

        public bool Editable
        {
            get { return true; }
        }

        public string Path
        {
            get { return string.Empty; }
        }

        public void Add()
        {
            _vm.Add();
        }

        public void Delete()
        {
            _vm.Delete();
        }

        public void Save()
        {
            _vm.Save();
        }

        private void view_CellValueChanged(object sender, CellValueChangedEventArgs e)
        {
            Save();
        }

        private void Button_Click_AddPhoto(object sender, RoutedEventArgs e)
        {
            if (_vm.UploadPhoto())
            {
                Gcl_Rubbings.RefreshRow(Gcl_Rubbings.View.FocusedRowHandle);
            }
        }


        private void Button_Click_Browse(object sender, RoutedEventArgs e)
        {
            NavigateToPageEventArgs arg = new NavigateToPageEventArgs();
            DevRubbingPhotos p = new DevRubbingPhotos(_vm.Cvs.View.CurrentItem as T_Rubbing);
            arg.ToPage = p;
            NavigateToPage(this, arg);
        }

        public event EventHandler<NavigateToPageEventArgs> NavigateToPage;
    }
}
